<?php
require_once dirname(__FILE__) . '/../includes/common.inc.php';
require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';


 $pdfname =  file_get_contents('emailtemplate.html');
 
$lag = abs(LAG);

$sqlorder = "SELECT e_oid,customerId FROM ns_v1myorder  WHERE disposalstatus = 0 AND isemail = 1 AND finished = 0 AND DATEDIFF(LEFT(FROM_UNIXTIME(date+".$lag."),10),CURDATE()) >=60";
//die;

$ordermyarr = getall($sqlorder);


$timenow = strtotime(date("Y-m-d H:i:s"));
$account = 'auto';
 $typeid=3;

if(!empty($ordermyarr)){
	foreach ($ordermyarr as $orone){
		$sql="SELECT * FROM ns_produce WHERE branch ='".BRANCH."' AND pi_model ='".MODEL_NAME_PRECON."' AND orderId =".$orone->e_oid." AND state =1 ";
		
		$productarr = getall1($sql);
		
		if(!empty($productarr)){//假如存在precon而且还没有发送过邮件的
			$sqlcustomer = "select * from ns_v1customer where e_oid = ".$orone->customerId." limit 1";
			$customerinfo = getone($sqlcustomer);
			
			$paysec = getsecondpayment($orone->e_oid);
			
			$pdfname = str_replace("[Bride]", $customerinfo->bridename, $pdfname);
            $pdfname = str_replace("[Groom]", $customerinfo->groomname, $pdfname);
            $pdfname = str_replace("[XXXX.XX]", $paysec, $pdfname);
            
            $title='Precon  for Customer '.$orone->customerId;
             
            if(empty($customerinfo->brideemail) && empty($customerinfo->groomemail)){
            	resendEmail(MAIL_FROM1,$title,$pdfname,$orone->customerId,'',$account,$timenow,$typeid,$orone->e_oid);
            }else{
			//brideemail,groomemail
			    if(!empty($customerinfo->brideemail))  resendEmail($customerinfo->brideemail,$title,$pdfname,$orone->customerId,'',$account,$timenow,$typeid,$orone->e_oid);
			    if(!empty($customerinfo->groomemail))  resendEmail($customerinfo->groomemail,$title,$pdfname,$orone->customerId,'',$account,$timenow,$typeid,$orone->e_oid);
            }
			
		}
		
	}
}


//$sql="SELECT * FROM ns_produce WHERE branch ='".BRANCH."' AND pi_model ='".MODEL_NAME_PRECON."' AND orderId IN ";



 /*$to="2598870227@qq.com";
 $title='Precon';
 $content = $pdfname;
 $cusno = 1593;
 $attachname='a.pdf';
 $account = 'ad';
 $cnow = time();
 
 $typeid=3;*/
 //resendEmail($to,$title,$content,$cusno,$attachname,$account,$cnow,$typeid);
 
 
 

 
?>